package com.linewell.util;

import java.lang.reflect.Field;
import java.util.Map;

import org.springframework.data.mongodb.core.query.Update;


/**
 * File: UpdateUtils.java
 * Description: 更新数据集工具
 */

public class UpdateUtils {

	public static Update getUpdateParameter(Class<?> cls, Map<String, Object> map){

		Update result = new Update();
		try {
			for (Map.Entry<String, Object> entry : map.entrySet()) {
				Field field = null;
				try {
					field = cls.getDeclaredField(entry.getKey());
				} catch (Exception e){
					continue;
				}
				org.springframework.data.mongodb.core.mapping.Field f = field.getAnnotation(org.springframework.data.mongodb.core.mapping.Field.class);
				result.set(f.value(), entry.getValue());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
